home *** CD-ROM | disk | FTP | other *** search
/ Cream of the Crop 1 / Cream of the Crop 1.iso / PROGRAM / TGCBOR20.ARJ / TUTOR.COM / FRAMES.TXT < prev    next >
Text File  |  1991-08-27  |  6KB  |  250 lines

  1. FRAMES
  2. -------------------------------------------------------------------
  3.  
  4. Frames are the core items to the window manager. You create a frame
  5. using a pushimage then save the global variable stackptr to
  6. manipulate it and to recognise it. stackptr is of the TYPE
  7. imagestackptr. Since this is a pointer it will always be unique to
  8. the frame.
  9.  
  10. Here we create a frame that covers the area (50,50,200,150) on the
  11. screen.
  12.  
  13. BEGINFILE> frame1.c
  14.   /* -- frame1.c  */
  15.  
  16. #include "teglsys.h"
  17.  
  18. imagestkptr  ifs;
  19.  
  20.  
  21. void main(void)
  22. {
  23.  
  24.  
  25.   easytegl();
  26.   easyout();
  27.   pushimage(50,50,200,150);
  28.   ifs = stackptr;
  29.   teglsupervisor();
  30. }
  31.  
  32.  
  33.  
  34. ENDFILE>
  35.  
  36.  
  37. Notice that we start our program with tegleasy and easyout. It's a
  38. good idea to start your programs this way when you are first
  39. learning how to use the TEGL WINDOWS TOOLKIT because they provide a
  40. simplified startup and a way to exit the program.
  41.  
  42. Specifically tegleasy initializes the graphics system (autodectects
  43. the graphics hardware), the virtual memory manager, the window
  44. manager and it clears the screen too! Easyout places a button in
  45. the lower left corner of the screen that will terminate the program
  46. when it is clicked on. This may seem trivial but in a GUI there has
  47. to be an event to make the program finish, teglsupervisor never
  48. returns, it just loops waiting for an event.
  49.  
  50. This little program isn't very useful yet because all we have done
  51. is saved the area that this frame covers. If you run it you won't
  52. see anything on the screen to show where the frame is. However, if
  53. you click the right mouse button down and move it around the screen
  54. will will find that there is an invisible frame there that can been
  55. moved. The right mouse button can be used to click on and move any
  56. mobile frame. Lets change it by covering it with something so we
  57. can see it.
  58.  
  59.  
  60. BEGINFILE> frame2.c
  61.   /* -- frame2.c */
  62.  
  63. #include "teglsys.h"
  64.  
  65. imagestkptr  ifs;
  66.  
  67.  
  68. void main(void)
  69. {
  70.  
  71.  
  72.   easytegl();
  73.   easyout();
  74.   pushimage(50,50,200,150);
  75.   shadowbox(50,50,200,150);
  76.   ifs = stackptr;
  77.   teglsupervisor();
  78. }
  79.  
  80.  
  81.  
  82. ENDFILE>
  83.  
  84.  
  85. Here we have added a line calling the routine shadowbox. This just
  86. blanks the frame and places a shadowed edge around it. You could
  87. clear the frame by using the bar command like so:
  88.  
  89.        setviewport(0,0,getmaxx(),getmaxy(),0);
  90.        setfillstyle(SOLID_FILL,WHITE);
  91.        bar(50,50,200,150);
  92.        setcolor(BLACK);
  93.        rectangle(50,50,200,150);
  94.  
  95. This would blank the frame to white and draw a black line around
  96. it. shawdowbox isn't much more complicated, but it is ready to use.
  97.  
  98. You're probably wondering why we keep saving the stackptr. Like we
  99. said earlier, you'll need this to manipulate the frame. So lets use
  100. it.
  101.  
  102. The next example adds a button and an associated event to the
  103. frame.
  104.  
  105.  
  106. BEGINFILE> frame3.c
  107.   /* -- frame3.c */
  108.  
  109. #include "teglsys.h"
  110.  
  111. imagestkptr  ifs;
  112.  
  113.  
  114. unsigned cancelevent(imagestkptr  frame, msclickptr   mouse)
  115.   {
  116.     dropstackimage(ifs);
  117.     return 0;
  118.   }
  119.  
  120.  
  121. void main(void)
  122. {
  123.  
  124.  
  125.   easytegl();
  126.   easyout();
  127.   pushimage(50,50,200,150);
  128.   shadowbox(50,50,200,150);
  129.   ifs = stackptr;
  130.   definesquarebuttontext(ifs,0,0,80,30,5,5,"CANCEL",cancelevent);
  131.   teglsupervisor();
  132. }
  133.  
  134.  
  135.  
  136. ENDFILE>
  137.  
  138.  
  139. After compiling and running this you'll probably agree that those
  140. squarebuttons look OK.
  141.  
  142. Now lets add some action to it. This example will press and release
  143. the button. Try holding the left mouse button down and passing it
  144. over the button repeatedly.
  145.  
  146. BEGINFILE> frame4.c
  147.   /* -- frame4.c */
  148.  
  149. #include "teglsys.h"
  150.  
  151. imagestkptr  ifs;
  152.  
  153.  
  154. unsigned cancelevent(imagestkptr  frame, msclickptr   mouse)
  155.   {
  156.       /* -- this will press the button down and if the mouse button  */
  157.       /* -- is release WHILE it is over the button it will return  */
  158.       /* -- TRUE. If the mouse cursor passes out of the button without  */
  159.       /* -- being released then it will return FALSE and  */
  160.       /* -- releasesquarebutton will be called automatically.  */
  161.     if (visualsquarebuttonpress(frame,mouse))
  162.       {
  163.       /* -- was TRUE, we release the button  */
  164.     releasesquarebutton(frame,mouse);
  165.       /* -- then dispose of the frame.  */
  166.     dropstackimage(ifs);
  167.       }
  168.     return 0;
  169.   }
  170.  
  171.  
  172. void main(void)
  173. {
  174.  
  175.  
  176.   easytegl();
  177.   easyout();
  178.   pushimage(50,50,200,150);
  179.   shadowbox(50,50,200,150);
  180.   ifs = stackptr;
  181.   definesquarebuttontext(ifs,0,0,70,30,5,5,"CANCEL",cancelevent);
  182.   teglsupervisor();
  183. }
  184.  
  185.  
  186.  
  187. ENDFILE>
  188.  
  189. At some point you will likely have more than one frame on the
  190. screen. When the mouse clicks on that frame it would be nice to
  191. have it on top of all the other frames.
  192.  
  193. setautorotate(OnOff: Boolean);
  194.  
  195. This sets the automatic rotation of frames. If set to TRUE then any
  196. frame that is clicked on will come to the top of the stack (be the
  197. topmost, and entirely visible).
  198.  
  199. This example will put 25 frames on the screen. Try running it with
  200. autorotate set to FALSE also. Try moving the frames around (using
  201. the right mouse button).
  202.  
  203. BEGINFILE> frame5.c
  204.   /* -- frame5.c */
  205.  
  206. #include "teglsys.h"
  207.  
  208.  
  209. unsigned cancelevent(imagestkptr  frame, msclickptr   mouse)
  210.   {
  211.     if (visualsquarebuttonpress(frame,mouse))
  212.       {
  213.       /* -- was TRUE, we release the button  */
  214.     releasesquarebutton(frame,mouse);
  215.       /* -- then dispose of the frame.  */
  216.     dropstackimage(frame);
  217.       }
  218.     return 0;
  219.   }
  220.  
  221. imagestkptr  ifs;
  222.     int      i;
  223.     unsigned x1, y1, x2, y2;
  224.  
  225.  
  226. void main(void)
  227. {
  228.  
  229.  
  230.   easytegl();
  231.   easyout();
  232.   setautorotate(TRUE);
  233.   for (i = 1; i <= 25; i++)
  234.     {
  235.       x1 = i * 10;
  236.       y1 = i * 10;
  237.       x2 = 150;
  238.       y2 = 100;
  239.       quickframe(&ifs,&x1,&y1,&x2,&y2);
  240.       definesquarebuttontext(ifs,0,0,70,30,5,5,"CANCEL",cancelevent);
  241.     }
  242.   teglsupervisor();
  243. }
  244.  
  245.  
  246.  
  247. ENDFILE>
  248.  
  249.  
  250.